home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / i-cpthre.adb < prev    next >
Text File  |  1996-01-30  |  25KB  |  825 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUNTIME LIBRARY (GNARL) COMPONENTS               --
  4. --                                                                          --
  5. --                 I N T E R F A C E S . C . P T H R E A D S                --
  6. --                                                                          --
  7. --                                  B o d y                                 --
  8. --                                                                          --
  9. --                             $Revision: 1.4 $                             --
  10. --                                                                          --
  11. --       Copyright (c) 1991,1992,1993,1994, FSU, All Rights Reserved        --
  12. --                                                                          --
  13. -- GNARL is free software; you can redistribute it  and/or modify it  under --
  14. -- terms  of  the  GNU  Library General Public License  as published by the --
  15. -- Free Software  Foundation;  either version 2, or (at  your  option)  any --
  16. -- later  version.  GNARL is distributed  in the hope that  it will be use- --
  17. -- ful, but but WITHOUT ANY WARRANTY;  without even the implied warranty of --
  18. -- MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Gen- --
  19. -- eral Library Public License  for more details.  You should have received --
  20. -- a  copy of the GNU Library General Public License along with GNARL;  see --
  21. -- file COPYING.LIB.  If not,  write to the  Free Software Foundation,  675 --
  22. -- Mass Ave, Cambridge, MA 02139, USA.                                      --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System;
  27.  
  28. with Interfaces.C.POSIX_RTE;
  29. --  Used for, Signal,
  30. --            Signal_Set
  31.  
  32. with Interfaces.C.POSIX_error; use Interfaces.C.POSIX_error;
  33. --  Used for, Return_Code
  34. --            Failure
  35.  
  36. with Interfaces.C.POSIX_Timers;
  37. --  Used for, timespec
  38.  
  39. with Unchecked_Conversion;
  40.  
  41. package body Interfaces.C.Pthreads is
  42.  
  43.    --  These unchecked conversion functions are used to convert a variable
  44.    --  to an access value referencing that variable.  The expression
  45.    --  Address_to_Pointer(X'Address) evaluates to an access value referencing
  46.    --  X; if X is of type T, this expression returns a value of type
  47.    --  access T.  This is necessary to allow structures to be passed to
  48.    --  C functions, since some compiler interfaces to C only allows scalers,
  49.    --  access values, and values of type System.Address as actual parameters.
  50.  
  51.    --  ??? it would be better to use the routines in System.Storage_Elements
  52.    --  ??? for conversion between pointers and access values. In any case
  53.    --  ??? I don't see the point of these conversions at all, why not pass
  54.    --  ??? Address values directly to the C routines (I = RBKD)
  55.  
  56.    Failure : POSIX_Error.Return_Code renames POSIX_Error.Failure;
  57.  
  58.    function Address_to_Pointer is new
  59.      Unchecked_Conversion (System.Address, POSIX_RTE.sigset_t_ptr);
  60.  
  61.    type pthread_t_ptr is access pthread_t;
  62.  
  63.    function Address_to_Pointer is new
  64.      Unchecked_Conversion (System.Address, pthread_t_ptr);
  65.  
  66.    type pthread_attr_t_ptr is access pthread_attr_t;
  67.  
  68.    function Address_to_Pointer is new
  69.      Unchecked_Conversion (System.Address, pthread_attr_t_ptr);
  70.  
  71.    type pthread_mutexattr_t_ptr is access pthread_mutexattr_t;
  72.  
  73.    function Address_to_Pointer is new
  74.      Unchecked_Conversion (System.Address, pthread_mutexattr_t_ptr);
  75.  
  76.    type pthread_mutex_t_ptr is access pthread_mutex_t;
  77.  
  78.    function Address_to_Pointer is new
  79.      Unchecked_Conversion (System.Address, pthread_mutex_t_ptr);
  80.  
  81.    type pthread_condattr_t_ptr is access pthread_condattr_t;
  82.  
  83.    function Address_to_Pointer is new
  84.      Unchecked_Conversion (System.Address, pthread_condattr_t_ptr);
  85.  
  86.    type pthread_cond_t_ptr is access pthread_cond_t;
  87.  
  88.    function Address_to_Pointer is new
  89.      Unchecked_Conversion (System.Address, pthread_cond_t_ptr);
  90.  
  91.    type pthread_key_t_ptr is access pthread_key_t;
  92.  
  93.    function Address_to_Pointer is new
  94.      Unchecked_Conversion (System.Address, pthread_key_t_ptr);
  95.  
  96.    type Address_Pointer is access System.Address;
  97.  
  98.    function Address_to_Pointer is new
  99.      Unchecked_Conversion (System.Address, Address_Pointer);
  100.  
  101.    type timespec_ptr is access POSIX_Timers.timespec;
  102.  
  103.    function Address_to_Pointer is new
  104.      Unchecked_Conversion (System.Address, timespec_ptr);
  105.  
  106.    type Int_Ptr is access int;
  107.  
  108.    function Address_to_Pointer is new
  109.      Unchecked_Conversion (System.Address, Int_Ptr);
  110.  
  111.    -----------------------
  112.    -- pthread_attr_init --
  113.    -----------------------
  114.  
  115.    procedure pthread_attr_init
  116.      (attributes : out pthread_attr_t;
  117.       result     : out Return_Code)
  118.    is
  119.       function pthread_attr_init_base
  120.         (attr : pthread_attr_t_ptr)
  121.          return Return_Code;
  122.       pragma Import (C, pthread_attr_init_base, "pthread_attr_init");
  123.  
  124.    begin
  125.       result :=
  126.         pthread_attr_init_base (Address_to_Pointer (attributes'Address));
  127.    end pthread_attr_init;
  128.  
  129.    --------------------------
  130.    -- pthread_attr_destroy --
  131.    --------------------------
  132.  
  133.    procedure pthread_attr_destroy
  134.      (attributes : in out pthread_attr_t;
  135.       result     : out Return_Code)
  136.    is
  137.       function pthread_attr_destroy_base
  138.         (attr : pthread_attr_t_ptr)
  139.          return Return_Code;
  140.       pragma Import (C, pthread_attr_destroy_base, "pthread_attr_destroy");
  141.  
  142.    begin
  143.       result :=
  144.         pthread_attr_destroy_base (Address_to_Pointer (attributes'Address));
  145.    end pthread_attr_destroy;
  146.  
  147.    -------------------------------
  148.    -- pthread_attr_setstacksize --
  149.    -------------------------------
  150.  
  151.    procedure pthread_attr_setstacksize
  152.      (attr      : in out pthread_attr_t;
  153.       stacksize : size_t;
  154.       result    : out Return_Code)
  155.    is
  156.       function pthread_attr_setstacksize_base
  157.         (attr      : pthread_attr_t_ptr;
  158.          stacksize : size_t)
  159.          return      Return_Code;
  160.       pragma Import
  161.         (C, pthread_attr_setstacksize_base, "pthread_attr_setstacksize");
  162.  
  163.    begin
  164.       result :=
  165.         pthread_attr_setstacksize_base
  166.           (Address_to_Pointer (attr'Address), stacksize);
  167.    end pthread_attr_setstacksize;
  168.  
  169.    ---------------------------------
  170.    -- pthread_attr_setdetachstate --
  171.    ---------------------------------
  172.  
  173.    procedure pthread_attr_setdetachstate
  174.      (attr        : in out pthread_attr_t;
  175.       detachstate : int;
  176.       result      : out Return_Code)
  177.    is
  178.       function pthread_attr_setdetachstate_base
  179.         (attr        : pthread_attr_t_ptr;
  180.          detachstate : Int_Ptr)
  181.          return        Return_Code;
  182.       pragma Import
  183.         (C, pthread_attr_setdetachstate_base, "pthread_attr_setdetachstate");
  184.  
  185.    begin
  186.       Result :=
  187.         pthread_attr_setdetachstate_base (
  188.           Address_to_Pointer (attr'Address),
  189.           Address_to_Pointer (detachstate'Address));
  190.    end pthread_attr_setdetachstate;
  191.  
  192.    --------------------
  193.    -- pthread_create --
  194.    --------------------
  195.  
  196.    procedure pthread_create
  197.      (thread        : out pthread_t;
  198.       attributes    : pthread_attr_t;
  199.       start_routine : System.Address;
  200.       arg           : System.Address;
  201.       result        : out Return_Code)
  202.    is
  203.       function pthread_create_base
  204.         (thread        : pthread_t_ptr;
  205.          attr          : pthread_attr_t_ptr;
  206.          start_routine : System.Address; arg : System.Address)
  207.          return          Return_Code;
  208.       pragma Import (C, pthread_create_base, "pthread_create");
  209.  
  210.    begin
  211.       result :=
  212.         pthread_create_base (Address_to_Pointer (thread'Address),
  213.           Address_to_Pointer (attributes'Address), start_routine, arg);
  214.    end pthread_create;
  215.  
  216.    ------------------
  217.    -- pthread_init --
  218.    ------------------
  219.  
  220.    --  This procedure provides a hook into Pthreads initialization that allows
  221.    --  the addition of initializations specific to the Ada Pthreads interface
  222.  
  223.    procedure pthread_init is
  224.       procedure pthread_init_base;
  225.       pragma Import (C, pthread_init_base, "pthread_init");
  226.  
  227.    begin
  228.       pthread_init_base;
  229.    end pthread_init;
  230.  
  231.    --------------------
  232.    -- pthread_detach --
  233.    --------------------
  234.  
  235.    procedure pthread_detach
  236.      (thread : in out pthread_t;
  237.       result : out Return_Code)
  238.    is
  239.       function pthread_detach_base
  240.         (thread : pthread_t_ptr)
  241.          return   Return_Code;
  242.       pragma Import (C, pthread_detach_base, "pthread_detach");
  243.  
  244.    begin
  245.       result := pthread_detach_base (Address_to_Pointer (thread'Address));
  246.    end pthread_detach;
  247.  
  248.    ----------------------------
  249.    -- pthread_mutexattr_init --
  250.    ----------------------------
  251.  
  252.    procedure pthread_mutexattr_init
  253.      (attributes : out pthread_mutexattr_t;
  254.       result     : out Return_Code)
  255.    is
  256.       function pthread_mutexattr_init_base
  257.         (attr : pthread_mutexattr_t_ptr)
  258.          return Return_Code;
  259.       pragma Import (C, pthread_mutexattr_init_base, "pthread_mutexattr_init");
  260.  
  261.    begin
  262.       result :=
  263.         pthread_mutexattr_init_base (Address_to_Pointer (attributes'Address));
  264.    end pthread_mutexattr_init;
  265.  
  266.    -----------------------------------
  267.    -- pthread_mutexattr_setprotocol --
  268.    -----------------------------------
  269.  
  270.    procedure pthread_mutexattr_setprotocol
  271.      (attributes : in out pthread_mutexattr_t;
  272.       protocol   : pthread_protocol_t;
  273.       result     : out Return_Code)
  274.    is
  275.       function pthread_mutexattr_setprotocol_base
  276.         (attributes : pthread_mutexattr_t_ptr;
  277.          protocol   : pthread_protocol_t)
  278.          return       Return_Code;
  279.       pragma Import
  280.         (C, pthread_mutexattr_setprotocol_base,
  281.             "pthread_mutexattr_setprotocol");
  282.  
  283.    begin
  284.       result :=
  285.         pthread_mutexattr_setprotocol_base
  286.           (Address_to_Pointer (attributes'Address), protocol);
  287.    end pthread_mutexattr_setprotocol;
  288.  
  289.    ---------------------------------------
  290.    -- pthread_mutexattr_setprio_ceiling --
  291.    ---------------------------------------
  292.  
  293.    procedure pthread_mutexattr_setprio_ceiling
  294.      (attributes   : in out pthread_mutexattr_t;
  295.       prio_ceiling : int;
  296.       result       : out Return_Code)
  297.    is
  298.       function pthread_mutexattr_setprio_ceiling_base
  299.         (attributes   : pthread_mutexattr_t_ptr;
  300.          prio_ceiling : int)
  301.          return         Return_Code;
  302.       pragma Import
  303.         (C, pthread_mutexattr_setprio_ceiling_base,
  304.             "pthread_mutexattr_setprio_ceiling");
  305.  
  306.    begin
  307.       result :=
  308.         pthread_mutexattr_setprio_ceiling_base (
  309.           Address_to_Pointer (attributes'Address), prio_ceiling);
  310.    end pthread_mutexattr_setprio_ceiling;
  311.  
  312.    ------------------------
  313.    -- pthread_mutex_init --
  314.    ------------------------
  315.  
  316.    procedure pthread_mutex_init
  317.      (mutex      : out pthread_mutex_t;
  318.       attributes : pthread_mutexattr_t;
  319.       result     : out Return_Code)
  320.    is
  321.       function pthread_mutex_init_base
  322.         (mutex : pthread_mutex_t_ptr;
  323.          attr  : pthread_mutexattr_t_ptr)
  324.          return  Return_Code;
  325.       pragma Import
  326.         (C, pthread_mutex_init_base, "pthread_mutex_init");
  327.  
  328.    begin
  329.       result :=
  330.         pthread_mutex_init_base (Address_to_Pointer (mutex'Address),
  331.           Address_to_Pointer (attributes'Address));
  332.    end pthread_mutex_init;
  333.  
  334.    ---------------------------
  335.    -- pthread_mutex_destroy --
  336.    ---------------------------
  337.  
  338.    procedure pthread_mutex_destroy
  339.      (mutex  : in out pthread_mutex_t;
  340.       result : out Return_Code)
  341.    is
  342.       function pthread_mutex_destroy_base
  343.         (mutex : pthread_mutex_t_ptr)
  344.          return  Return_Code;
  345.       pragma Import (C, pthread_mutex_destroy_base, "pthread_mutex_destroy");
  346.  
  347.    begin
  348.       result :=
  349.         pthread_mutex_destroy_base (Address_to_Pointer (mutex'Address));
  350.    end pthread_mutex_destroy;
  351.  
  352.    ---------------------------
  353.    -- pthread_mutex_trylock --
  354.    ---------------------------
  355.  
  356.    procedure pthread_mutex_trylock
  357.      (mutex  : in out pthread_mutex_t;
  358.       result : out Return_Code)
  359.    is
  360.       function pthread_mutex_trylock_base
  361.         (mutex : pthread_mutex_t_ptr)
  362.          return  Return_Code;
  363.       pragma Import (C, pthread_mutex_trylock_base, "pthread_mutex_trylock");
  364.  
  365.    begin
  366.       result :=
  367.         pthread_mutex_trylock_base (Address_to_Pointer (mutex'Address));
  368.    end pthread_mutex_trylock;
  369.  
  370.    ------------------------
  371.    -- pthread_mutex_lock --
  372.    ------------------------
  373.  
  374.    procedure pthread_mutex_lock
  375.      (mutex  : in out pthread_mutex_t;
  376.       result : out Return_Code)
  377.    is
  378.       function pthread_mutex_lock_base
  379.         (mutex : pthread_mutex_t_ptr)
  380.          return Return_Code;
  381.       pragma Import (C, pthread_mutex_lock_base, "pthread_mutex_lock");
  382.  
  383.    begin
  384.       result := pthread_mutex_lock_base (Address_to_Pointer (mutex'Address));
  385.    end pthread_mutex_lock;
  386.  
  387.    --------------------------
  388.    -- pthread_mutex_unlock --
  389.    --------------------------
  390.  
  391.    procedure pthread_mutex_unlock
  392.      (mutex  : in out pthread_mutex_t;
  393.       result : out Return_Code)
  394.    is
  395.       function pthread_mutex_unlock_base
  396.         (mutex : pthread_mutex_t_ptr)
  397.          return Return_Code;
  398.       pragma Import (C, pthread_mutex_unlock_base, "pthread_mutex_unlock");
  399.  
  400.    begin
  401.       result := pthread_mutex_unlock_base (Address_to_Pointer (mutex'Address));
  402.    end pthread_mutex_unlock;
  403.  
  404.    -----------------------
  405.    -- pthread_cond_init --
  406.    -----------------------
  407.  
  408.    procedure pthread_cond_init
  409.      (condition  : out pthread_cond_t;
  410.       attributes : pthread_condattr_t;
  411.       result     : out Return_Code)
  412.    is
  413.       function pthread_cond_init_base
  414.         (cond : pthread_cond_t_ptr;
  415.          attr : pthread_condattr_t_ptr)
  416.          return Return_Code;
  417.       pragma Import (C, pthread_cond_init_base, "pthread_cond_init");
  418.  
  419.    begin
  420.       result :=
  421.         pthread_cond_init_base (Address_to_Pointer (condition'Address),
  422.           Address_to_Pointer (attributes'Address));
  423.    end pthread_cond_init;
  424.  
  425.    -----------------------
  426.    -- pthread_cond_wait --
  427.    -----------------------
  428.  
  429.    procedure pthread_cond_wait
  430.      (condition : in out pthread_cond_t;
  431.       mutex     : in out pthread_mutex_t;
  432.       result    : out Return_Code)
  433.    is
  434.       function pthread_cond_wait_base
  435.         (cond  : pthread_cond_t_ptr;
  436.          mutex : pthread_mutex_t_ptr)
  437.          return  Return_Code;
  438.       pragma Import (C, pthread_cond_wait_base, "pthread_cond_wait");
  439.  
  440.    begin
  441.       result :=
  442.         pthread_cond_wait_base (Address_to_Pointer (condition'Address),
  443.           Address_to_Pointer (mutex'Address));
  444.    end pthread_cond_wait;
  445.  
  446.    ----------------------------
  447.    -- pthread_cond_timedwait --
  448.    ----------------------------
  449.  
  450.    procedure pthread_cond_timedwait
  451.      (condition     : in out pthread_cond_t;
  452.       mutex         : in out pthread_mutex_t;
  453.       absolute_time : POSIX_Timers.timespec;
  454.       result        : out Return_Code)
  455.    is
  456.       function pthread_cond_timedwait_base
  457.         (cond    : pthread_cond_t_ptr;
  458.          mutex   : pthread_mutex_t_ptr;
  459.          abstime : timespec_ptr)
  460.          return    Return_Code;
  461.       pragma Import (C, pthread_cond_timedwait_base, "pthread_cond_timedwait");
  462.  
  463.    begin
  464.       result :=
  465.         pthread_cond_timedwait_base (
  466.           Address_to_Pointer (condition'Address),
  467.           Address_to_Pointer (mutex'Address),
  468.           Address_to_Pointer (absolute_time'Address));
  469.    end pthread_cond_timedwait;
  470.  
  471.    -------------------------
  472.    -- pthread_cond_signal --
  473.    -------------------------
  474.  
  475.    procedure pthread_cond_signal
  476.      (condition : in out pthread_cond_t;
  477.       result    : out Return_Code)
  478.    is
  479.       function pthread_cond_signal_base
  480.         (cond : pthread_cond_t_ptr)
  481.          return Return_Code;
  482.       pragma Import (C, pthread_cond_signal_base, "pthread_cond_signal");
  483.  
  484.    begin
  485.       result :=
  486.         pthread_cond_signal_base (Address_to_Pointer (condition'Address));
  487.    end pthread_cond_signal;
  488.  
  489.    ----------------------------
  490.    -- pthread_cond_broadcast --
  491.    ----------------------------
  492.  
  493.    procedure pthread_cond_broadcast
  494.      (condition : in out pthread_cond_t;
  495.       result    : out Return_Code)
  496.    is
  497.       function pthread_cond_broadcast_base
  498.         (cond : pthread_cond_t_ptr)
  499.          return Return_Code;
  500.       pragma Import (C, pthread_cond_broadcast_base, "pthread_cond_broadcast");
  501.  
  502.    begin
  503.       result :=
  504.         pthread_cond_broadcast_base (Address_to_Pointer (condition'Address));
  505.    end pthread_cond_broadcast;
  506.  
  507.    --------------------------
  508.    -- pthread_cond_destroy --
  509.    --------------------------
  510.  
  511.    procedure pthread_cond_destroy
  512.      (condition : in out pthread_cond_t;
  513.       result    : out Return_Code)
  514.    is
  515.       function pthread_cond_destroy_base
  516.         (cond : pthread_condattr_t_ptr)
  517.          return Return_Code;
  518.       pragma Import (C, pthread_cond_destroy_base, "pthread_cond_destroy");
  519.  
  520.    begin
  521.       result :=
  522.         pthread_cond_destroy_base (Address_to_Pointer (condition'Address));
  523.    end pthread_cond_destroy;
  524.  
  525.    ---------------------------
  526.    -- pthread_condattr_init --
  527.    ---------------------------
  528.  
  529.    procedure pthread_condattr_init
  530.      (attributes : out pthread_condattr_t;
  531.       result     : out Return_Code)
  532.    is
  533.       function pthread_condattr_init_base
  534.         (cond : pthread_condattr_t_ptr)
  535.          return Return_Code;
  536.       pragma Import (C, pthread_condattr_init_base, "pthread_condattr_init");
  537.  
  538.    begin
  539.       result :=
  540.         pthread_condattr_init_base (Address_to_Pointer (attributes'Address));
  541.    end pthread_condattr_init;
  542.  
  543.    ------------------------------
  544.    -- pthread_condattr_destroy --
  545.    ------------------------------
  546.  
  547.    procedure pthread_condattr_destroy
  548.      (attributes : in out pthread_condattr_t;
  549.       result     : out Return_Code)
  550.    is
  551.       function pthread_condattr_destroy_base
  552.         (cond : pthread_condattr_t_ptr)
  553.          return Return_Code;
  554.       pragma Import
  555.         (C, pthread_condattr_destroy_base, "pthread_condattr_destroy");
  556.  
  557.    begin
  558.       result :=
  559.         pthread_condattr_destroy_base
  560.           (Address_to_Pointer (attributes'Address));
  561.    end pthread_condattr_destroy;
  562.  
  563.    -------------------------
  564.    -- pthread_setspecific --
  565.    -------------------------
  566.  
  567.    --  Suppress all checks to prevent stack check on entering routine
  568.    --  which routine does this comment belong in???
  569.    --  need pragma Suppress in spec for routine???
  570.    --  Also need documentation of why suppress is needed ???
  571.  
  572.    procedure pthread_setspecific
  573.      (key    : pthread_key_t;
  574.       value  : System.Address;
  575.       result : out Return_Code)
  576.    is
  577.       function pthread_setspecific_base
  578.         (key   : pthread_key_t;
  579.          value : System.Address)
  580.          return  Return_Code;
  581.       pragma Import (C, pthread_setspecific_base, "pthread_setspecific");
  582.  
  583.    begin
  584.       result := pthread_setspecific_base (key, value);
  585.    end pthread_setspecific;
  586.  
  587.    -------------------------
  588.    -- pthread_getspecific --
  589.    -------------------------
  590.  
  591.    procedure pthread_getspecific
  592.      (key    : pthread_key_t;
  593.       value  : out System.Address;
  594.       result : out Return_Code)
  595.    is
  596.       function pthread_getspecific_base
  597.         (key   : pthread_key_t;
  598.          value : Address_Pointer)
  599.          return  Return_Code;
  600.       pragma Import (C, pthread_getspecific_base, "pthread_getspecific");
  601.  
  602.    begin
  603.       result :=
  604.         pthread_getspecific_base (key, Address_to_Pointer (value'Address));
  605.    end pthread_getspecific;
  606.  
  607.    ------------------------
  608.    -- pthread_key_create --
  609.    ------------------------
  610.  
  611.    procedure pthread_key_create
  612.      (key        : out pthread_key_t;
  613.       destructor : System.Address;
  614.       result     : out Return_Code)
  615.    is
  616.       function pthread_key_create_base
  617.         (key        : pthread_key_t_ptr;
  618.          destructor : System.Address)
  619.          return       Return_Code;
  620.       pragma Import (C, pthread_key_create_base, "pthread_key_create");
  621.  
  622.    begin
  623.       result :=
  624.         pthread_key_create_base (Address_to_Pointer (key'Address), destructor);
  625.    end pthread_key_create;
  626.  
  627.    --------------------------
  628.    -- pthread_attr_setprio --
  629.    --------------------------
  630.  
  631.    procedure pthread_attr_setprio
  632.      (attr     : in out pthread_attr_t;
  633.       priority : Priority_Type;
  634.       result   : out Return_Code)
  635.    is
  636.       function pthread_attr_setprio_base
  637.         (attr     : pthread_attr_t_ptr;
  638.          priority : Priority_Type)
  639.          return     Return_Code;
  640.       pragma Import (C, pthread_attr_setprio_base, "pthread_attr_setprio");
  641.  
  642.    begin
  643.       result :=
  644.         pthread_attr_setprio_base
  645.           (Address_to_Pointer (attr'Address), priority);
  646.    end pthread_attr_setprio;
  647.  
  648.    --------------------------
  649.    -- pthread_attr_getprio --
  650.    --------------------------
  651.  
  652.    procedure pthread_attr_getprio
  653.      (attr     : pthread_attr_t;
  654.       priority : out Priority_Type;
  655.       result   : out Return_Code)
  656.    is
  657.       Temp_Result : Return_Code;
  658.  
  659.       function pthread_attr_getprio_base
  660.         (attr : pthread_attr_t_ptr)
  661.          return Return_Code;
  662.       pragma Import (C, pthread_attr_getprio_base, "pthread_attr_getprio");
  663.  
  664.    begin
  665.       Temp_Result :=
  666.         pthread_attr_getprio_base (Address_to_Pointer (attr'Address));
  667.  
  668.       if Temp_Result /= Failure then
  669.          priority := Priority_Type (Temp_Result);
  670.          result := 0;
  671.  
  672.       --  For failure case, send out lowest priority (is it OK ???)
  673.  
  674.       else
  675.          priority := Priority_Type'First;
  676.          result := Failure;
  677.       end if;
  678.  
  679.    end pthread_attr_getprio;
  680.  
  681.    --------------------------
  682.    -- pthread_setschedattr --
  683.    --------------------------
  684.  
  685.    procedure pthread_setschedattr
  686.      (thread     : pthread_t;
  687.       attributes : pthread_attr_t;
  688.       result     : out Return_Code)
  689.    is
  690.       function pthread_setschedattr_base
  691.         (thread : pthread_t;
  692.          attr   : pthread_attr_t_ptr)
  693.          return   Return_Code;
  694.       pragma Import (C, pthread_setschedattr_base, "pthread_setschedattr");
  695.  
  696.    begin
  697.       result :=
  698.         pthread_setschedattr_base (thread,
  699.           Address_to_Pointer (attributes'Address));
  700.    end pthread_setschedattr;
  701.  
  702.    --------------------------
  703.    -- pthread_getschedattr --
  704.    --------------------------
  705.  
  706.    procedure pthread_getschedattr
  707.      (thread      : pthread_t;
  708.       attributes  : out pthread_attr_t;
  709.       result      : out Return_Code)
  710.    is
  711.       function pthread_getschedattr_base
  712.         (thread : pthread_t;
  713.          attr   : pthread_attr_t_ptr)
  714.          return   Return_Code;
  715.       pragma Import (C, pthread_getschedattr_base, "pthread_getschedattr");
  716.  
  717.    begin
  718.       result :=
  719.         pthread_getschedattr_base (thread,
  720.           Address_to_Pointer (attributes'Address));
  721.    end pthread_getschedattr;
  722.  
  723.    ------------------
  724.    -- pthread_self --
  725.    ------------------
  726.  
  727.    function pthread_self return pthread_t is
  728.       function pthread_self_base return pthread_t;
  729.       pragma Import (C, pthread_self_base, "pthread_self");
  730.  
  731.    begin
  732.       return pthread_self_base;
  733.    end pthread_self;
  734.  
  735.    -------------
  736.    -- sigwait --
  737.    -------------
  738.  
  739.    procedure sigwait
  740.      (set         : POSIX_RTE.Signal_Set;
  741.       sig         : out POSIX_RTE.Signal;
  742.       result      : out Return_Code)
  743.    is
  744.       Temp_Result : Return_Code;
  745.  
  746.       function sigwait_base
  747.         (set : POSIX_RTE.sigset_t_ptr) return Return_Code;
  748.       pragma Import (C, sigwait_base, "sigwait");
  749.  
  750.    begin
  751.       Temp_Result := sigwait_base (Address_to_Pointer (set'Address));
  752.  
  753.       if Temp_Result /= Failure then
  754.          sig := POSIX_RTE.Signal (Temp_Result);
  755.       else
  756.          sig := 0;
  757.       end if;
  758.  
  759.       result := Temp_Result;
  760.    end sigwait;
  761.  
  762.    ------------------
  763.    -- pthread_kill --
  764.    ------------------
  765.  
  766.    procedure pthread_kill
  767.      (thread : pthread_t;
  768.       sig    : POSIX_RTE.Signal;
  769.       result : out Return_Code)
  770.    is
  771.       function pthread_kill_base
  772.         (thread : pthread_t;
  773.          sig    : POSIX_RTE.Signal)
  774.          return   Return_Code;
  775.       pragma Import (C, pthread_kill_base, "pthread_kill");
  776.  
  777.    begin
  778.       result := pthread_kill_base (thread, sig);
  779.    end pthread_kill;
  780.  
  781.    --------------------------
  782.    -- pthread_cleanup_push --
  783.    --------------------------
  784.  
  785.    procedure pthread_cleanup_push
  786.      (routine : System.Address;
  787.       arg     : System.Address)
  788.    is
  789.       procedure pthread_cleanup_push_base
  790.         (routine : System.Address;
  791.          arg     : System.Address);
  792.       pragma Import (C, pthread_cleanup_push_base, "pthread_cleanup_push");
  793.  
  794.    begin
  795.       pthread_cleanup_push_base (routine, arg);
  796.    end pthread_cleanup_push;
  797.  
  798.    -------------------------
  799.    -- pthread_cleanup_pop --
  800.    -------------------------
  801.  
  802.    procedure pthread_cleanup_pop (execute : int) is
  803.       procedure pthread_cleanup_pop_base (execute : int);
  804.       pragma Import (C, pthread_cleanup_pop_base, "pthread_cleanup_pop");
  805.  
  806.    begin
  807.       pthread_cleanup_pop_base (execute);
  808.    end pthread_cleanup_pop;
  809.  
  810.    -------------------
  811.    -- pthread_yield --
  812.    -------------------
  813.  
  814.    procedure pthread_yield is
  815.       procedure pthread_yield_base;
  816.       pragma Import (C, pthread_yield_base, "pthread_yield");
  817.  
  818.    begin
  819.       pthread_yield_base;
  820.    end pthread_yield;
  821.  
  822. begin
  823.    pthread_init;
  824. end Interfaces.C.Pthreads;
  825.